package com.example.demo.hutool.redis.pipeline;

import com.example.demo.hutool.redis.RedisTypeTest;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Pipeline;

import java.util.List;

public class PipelineTypeTest {


    public static void main(String[] args) {
        jedisPipelineQueryList();
    }

    public static void jedisPipelineQueryList() {
        JedisPool jedisPool = RedisTypeTest.getJedisPool();
        Jedis jedis = jedisPool.getResource();

        //开启redis管道
        Pipeline pipeline = jedis.pipelined();
        String[] strings = new String[100000];
        for (int i = 0; i < 100000; i++) {
            strings[i] = i + "";
        }
        int size = 1;
        long begin = System.currentTimeMillis();
        for (int i = 0; i < size; i++) {
            String key = i + "Pipelinelist";
            pipeline.lrange(key, 0, -1);
//            pipeline.lpush(key, strings);
        }
        List<Object> objects = pipeline.syncAndReturnAll();
        long end = System.currentTimeMillis();
        System.out.println("批量查询耗时" + (end - begin) + "毫秒");
        jedis.close();
        jedisPool.close();
    }

}
